package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.adminlogsInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface admin_logsMapper {

    @Select({
            "<script>",
            "SELECT * FROM admin_logs",
            "<where>",
            "  <if test='adminId != null'>AND admin_id = #{adminId}</if>",
            "  <if test='operationType != null'>AND operation_type = #{operationType}</if>",
            "</where>",
            "</script>"
    })
    List<adminlogsInfo> findAll(@Param("adminId") Integer adminId, @Param("operationType") String operationType);

    @Select("SELECT DISTINCT operation_type FROM admin_logs")
    List<String> getOperationTypes();

    @Insert("INSERT INTO admin_logs (admin_id, operation_type, target_id, target_type, operation_detail, ip_address, create_time) " +
            "VALUES (#{adminId}, #{operationType}, #{targetId}, #{targetType}, #{operationDetail}, #{ipAddress}, #{createTime})")
    int addLog(adminlogsInfo log);

    @Select("SELECT * FROM admin_logs")
    List<adminlogsInfo> findAllLogs();

    // 新增删除日志的方法
    @Delete("DELETE FROM admin_logs WHERE log_id = #{logId}")
    int deleteLog(@Param("logId") Integer logId);
}